<template>
  <div class="view_page userList">
    <el-card class="box-card">
      <!--卡片头部-->
      <div slot="header" class="clearfix">
        <!--左侧-->
        <!-- <div class="left">
          <div class="menu-title">
            模型文件管理
          </div>
        </div> -->
        <div class="left">
          <div class="back-page">
            <div class="add-back" @click="back">
              <i class="fa fa-arrow-left" aria-hidden="true"></i>
              <span>模型文件版本管理</span>
            </div>
          </div>
        </div>
        <!--右侧-->
        <div class="right">
          <el-button type="primary" size="small" @click="navtoAdd('add')"
            >新增
          </el-button>
        </div>
      </div>
      <!-- 卡片内容 -->
      <div>
        <el-table :data="datalist" style="width: 100%">
          <el-table-column prop="id" label="ID" align="center" min-width="80">
          </el-table-column>
          <el-table-column
            prop="modelOrgName"
            label="模型文件名称"
            align="center"
            min-width="90"
          >
          </el-table-column>
          <el-table-column
            prop="modelName"
            label="模型版本名"
            align="center"
            min-width="80"
          >
          </el-table-column>
          <el-table-column
            prop="position"
            label="模型位置"
            align="center"
            min-width="90"
          >
          </el-table-column>
          <el-table-column
            prop="rotation"
            label="模型旋转"
            align="center"
            min-width="90"
          >
          </el-table-column>
          <el-table-column
            prop="scale"
            label="模型缩放"
            align="center"
            min-width="90"
          >
          </el-table-column>
          <el-table-column
            prop="highlight_name"
            label="模型高亮物体名"
            align="center"
            min-width="110"
          >
          </el-table-column>
          <el-table-column
            prop="modelScanningPosition"
            label="模型扫描位置"
            align="center"
            min-width="90"
          >
          </el-table-column>
          <el-table-column
            prop="modelScanningRotation"
            label="模型扫描旋转"
            align="center"
            min-width="90"
          >
          </el-table-column>
          <el-table-column
            prop="modelScanningScale"
            label="模型扫描缩放"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="abPath"
            label="模型路径"
            align="center"
            min-width="120"
          >
          </el-table-column>
					<el-table-column
					  prop="centerPos"
					  label="centerPos"
					  align="center"
					  min-width="120"
					>
					</el-table-column>
          <el-table-column
            prop="version_num"
            label="版本号"
            align="center"
            min-width="80"
          >
          </el-table-column>
          <el-table-column
            prop="update_time"
            label="更新时间"
            align="center"
            min-width="90"
          >
          </el-table-column>
          <el-table-column
            prop="has_enable"
            label="状态"
            align="center"
            min-width="50"
          >
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.has_enable"
                @change="changestatus(scope.row)"
                inactive-color="#ff4949"
              >
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            min-width="160"
            align="center"
          >
            <template slot-scope="scope">
              <div style="display: flex;align-items: center;flex-wrap: wrap; ">
                <el-button
                  type="primary"
                  size="small"
                  @click="navtoAdd('update', scope.row)"
                  >修改
                </el-button>
                <el-button type="danger" size="small" @click="del(scope.row)"
                  >删除
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <!-- <pagination
          :total="total"
          :currentPage="pageNum"
          :pageSize="size"
          position="right"
          @search="searchPagination"
        >
        </pagination> -->
      </div>
    </el-card>
  </div>
</template>

<script>
import axios from "axios";
import qs from "qs";
import { Message } from "element-ui";
import pagination from "@/components/common/pagination/pagination";
import devConfig from "*/dev.config";

export default {
  components: {
    pagination
  },
  watch: {},
  data() {
    return {
      // 筛选内容
      TESTFROMDATA: {
        title: ""
      },

      itemID: "", //修改的id
      // 列表的数据
      datalist: [],
	  //启用的数据或第一条数据
	  dataEnable:'',
      pageNum: 1,
      page: 1,
      size: 10,
      total: 0
    };
  },
  created() {
    var _this = this;
    _this.itemID = _this.$route.query.data;
    _this.getListPage();
  },
  mounted() {},
  methods: {
    //查询列表
    getListPage() {
      var _this = this;
      var datas = {
        id: _this.itemID
      };
      _this.$apis.u_model_file_list(datas).then(res => {
        if (res.result == 0) {
          _this.datalist = res.data;
          // _this.total = res.rows;
          // _this.pageNum = res.page;
          // localStorage.setItem("page", 1);
		  let datalist = res.data
		  if(datalist.length!=0){
			  let dataEnable = ''
		  var ifEnable = datalist.findIndex(item=>{
			 return item.has_enable==true
		  })
		  if(ifEnable=='-1'){
			  dataEnable=datalist[0]
		  }else{
			  dataEnable=datalist[ifEnable] 
		  }
		_this.dataEnable = JSON.parse(JSON.stringify(dataEnable))
		  }
		 
		  
        }
      });
    },

    //模糊查询
    searchList() {
      this.page = 1;
      this.datalist = [];
      this.getListPage();
    },
    //分页
    searchPagination(page) {
      this.page = page;
      localStorage.setItem("page", page);
      this.getListPage();
    },
    // 新增修改
    navtoAdd(type, item) {
      var _this = this;
      localStorage.setItem("page", this.page);
      if (type == "add") {
        _this.$router.push({
          path: "/admin/modelFileManage/modelFileAdd",
          query: {
            type: type,
		     modelId:_this.itemID,
			 data:JSON.stringify(_this.dataEnable)
          }
        });
      } else {
        _this.$router.push({
          path: "/admin/modelFileManage/modelFileAdd",
          query: {
            type: type,
            data: JSON.stringify(item)
          }
        });
      }
    },
    //切换状态
    changestatus(item) {
      var _this = this;
      // console.log("item:", item);
      _this.$apis.u_model_file_update(item).then(res => {
        if (res.result == 0) {
          Message.success("修改成功");
          _this.getListPage();
        }
      });
    },
    //删除
    del(item) {
      var _this = this;
      var datas = {
        id: item.id
      };

      _this
        .$confirm("确定要删除此条吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(() => {
          _this.$apis.u_model_file_del(datas).then(res => {
            if (res.result == 0) {
              Message.success("删除成功");
              if (this.page > 1 && this.datalist.length <= 1) {
                this.page = this.page - 1;
              }
              _this.getListPage();
            }
          });
        })
        .catch(() => {});
    },
    back() {
      this.$router.back();
    }
  }
};
</script>

<style>
.el-table .cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal !important;
}
</style>
